package com.ziyucoding.springboot.labs.lab3.rocketmqdemo.producer;

import com.ziyucoding.springboot.labs.lab3.rocketmqdemo.message.Demo6Message;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 示例6的生产者（用于顺序消息）
 *
 * @author ziyucoding
 * @date 2022-10-24
 **/
@Component
public class Demo6Producer {

    @Autowired
    private RocketMQTemplate rocketMQTemplate;

    /**
     * 同步发送顺序消息
     *
     * @param id
     * @return org.apache.rocketmq.client.producer.SendResult
     **/
    public SendResult syncSendOrderly(Integer id) {
        // 创建消息
        Demo6Message message = new Demo6Message(id);
        // 同步发送消息
        SendResult result = rocketMQTemplate.syncSendOrderly(Demo6Message.TOPIC, message, String.valueOf(id));
        return result;
    }
}
